package com.ssm.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.sfzy.entity.ConsultWait;
import com.ssm.sfzy.mapper.ConsultWaitMapper;
import com.ssm.sfzy.mapper.TeacherMapper;
import com.ssm.sfzy.mapper.UserMapper;
import com.ssm.sfzy.service.ConsultWaitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ConsultWaitServiceImpl
 * @Description TODO
 * @Author Happy
 * @Date 2024年03月30日 16:45
 * @Version 1.0
 */
@Service
public class ConsultWaitServiceImpl implements ConsultWaitService {
    @Autowired
    private ConsultWaitMapper consultWaitMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private TeacherMapper teacherMapper;
    @Override
    public void add(ConsultWait entity) {
        consultWaitMapper.insert(entity);
    }

    @Override
    public void edit(ConsultWait entity) {
        consultWaitMapper.update(entity);
    }

    @Override
    public void remove(Integer id) {
        consultWaitMapper.delete(id);
    }

    @Override
    public void removeBatch(Integer[] ids) {
        consultWaitMapper.deleteBatch(ids);
    }

    @Override
    public List<ConsultWait> find(ConsultWait entity) {
        return consultWaitMapper.select(entity);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, ConsultWait entity) {
        //
        PageHelper.startPage(pageNum,pageSize);
        List<ConsultWait> list = consultWaitMapper.select(entity);
        for (ConsultWait consultWait : list){
            int teacherId = consultWait.getTeacherId();
            consultWait.setTeacherName(teacherMapper.selectById(teacherId).getName());
            consultWait.setUsername(userMapper.selectById(consultWait.getUserId()).getNickName());
        }
        //
        PageInfo<ConsultWait> pageInfo=new PageInfo<>(list);
        //整合处理
        Map<String,Object> map=new HashMap<>();
        map.put("list",pageInfo.getList());
        map.put("total",pageInfo.getTotal());
        return map;
    }

    @Override
    public ConsultWait findById(Integer id) {
        return consultWaitMapper.selectById(id);
    }
}
